package leetcode.jianzhioffer;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-06 14:48
 **/
public class JianZhiOffer55I {

    /*int depth;
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return depth;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        TreeNode temp = null;
        queue.offer(root);
        while (queue.size() != 0) {
            depth++;
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                temp = queue.poll();
                if (temp.left != null) {
                    queue.offer(temp.left);
                }
                if (temp.right != null) {
                    queue.offer(temp.right);
                }
            }
        }
        return depth;
    }*/

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }

}
